package com.xrui.hbase.filter;

import com.google.common.base.Objects;
import com.xrui.hbase.ColumnName;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.hadoop.hbase.filter.Filter;
import org.apache.hadoop.hbase.filter.KeyOnlyFilter;

import java.io.IOException;

/**
 * Column filter to strip the cell value.
 * <p>
 * <p> This filter is useful to retrieve the qualifiers and/or version timestamps in a column. </p>
 * <p>
 * <p>
 * even if this filter is attached to a subset of the columns only in a DataRequest.
 * For now, if you want to strip the value on specific columns within a data request,
 * you need to issue separate Get requests for this set of columns.
 * </p>
 */
public final class StripValueColumnFilter extends ColumnFilter {
    private static final long serialVersionUID = 1L;

    /**
     * All StripValueColumnFilter instances are the same: generate hash-code ahead of time.
     */
    private static final int HASH_CODE =
        new HashCodeBuilder().append(StripValueColumnFilter.class).toHashCode();

    /**
     * {@inheritDoc}
     */
    @Override
    public Filter toHBaseFilter(ColumnName columnName/*, Context context*/) throws IOException {
        return new KeyOnlyFilter();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public boolean equals(Object other) {
        // All StripValueRowFilters are the same.
        return other instanceof StripValueColumnFilter;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public int hashCode() {
        return HASH_CODE;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return Objects.toStringHelper(StripValueColumnFilter.class).toString();
    }
}
